import mongoose from '../config/DBHelper'
import moment from 'moment'

const Schema = mongoose.Schema
const PostTagsSchema = new Schema({
  name: { type: String },
  className: { type: String }
})

PostTagsSchema.pre('save', function (next) {
  this.created = moment().format('YYYY-MM-DD HH:mm:ss')
  next()
})

PostTagsSchema.statics = {
  /**
   * 获取标签列表数据
   * @param {Number} page 分页页数
   * @param {Number} limit
   */
  getList: function (page, limit) {
    return this.find()
      .skip(page * limit)
      .limit(limit)
  },
  getListCount: function (options = {}) {
    return this.find(options).countDocuments()
  }
}

const PostTagsModel = mongoose.model('post_tags', PostTagsSchema)

export default PostTagsModel
